package com.dsth.test.chat;

import junit.framework.Assert;

public class ChatDecoder {
	
	public static ChatMessage decode(byte[] buf) {
		String msg = new String(buf);
		String[] sp = msg.split("\r\n");
		ChatMessage result = new ChatMessage();
		int n = sp.length;
		Assert.assertTrue(n >=2);
		result.to = sp[0];
		result.from = sp[1];
		if (n > 2) {
			result.text = sp[2];
		}
		return result;
	}

}
